#ifndef __profiler
#define __profiler

#include <console.h>

extern console cons;

class profiler {

	string name;
	clock_t startt, endt;
	clock_t mint, maxt;
	public:
		profiler (const string& s) : name(s) {
			mint = -1;
			maxt = 0;
		}

		void start () {
			startt = clock();
		}

		void end () {
			endt = clock();
			clock_t elapsedt = endt - startt;
			if (mint == -1) mint = elapsedt;
				else if (elapsedt < mint) mint = elapsedt;
					else if (elapsedt > maxt) maxt = elapsedt;
		}

		friend console& operator<< (console& c, const profiler& p);


};

console& operator<< (console& c, const profiler& p) {
	cons << p.name << " min = " << ticks2secs (p.mint) << " max = " << ticks2secs (p.maxt);
	return c;
}
#endif
